<?php
/**
 * Zapp
 *
 * @version $Id: Application.php 20 2011-06-05 14:50:31Z dm.barsukov@gmail.com $
 */

/**
 * @namespace
 */
namespace Zapp\Application;

require_once ZAPP_FRAMEWORK_PATH . '/Zend/Application.php';
require_once ZAPP_FRAMEWORK_PATH . '/Zend/Loader/Autoloader.php';

class Application extends \Zend_Application
{
    /**
     * Constructor
     *
     * Initialize application. Potentially initializes include_paths, PHP
     * settings, and bootstrap class.
     *
     * @param  string                   $environment
     * @param  string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
     * @throws Zend_Application_Exception When invalid options are provided
     * @return void
     */
    public function __construct($environment, $options = null)
    {
        $this->_environment = (string) $environment;
        $this->setAutoloader(\Zend_Loader_Autoloader::getInstance());

        if (null !== $options) {
            if (is_string($options)) {
                $options = $this->_loadConfig($options);
            } elseif ($options instanceof \Zend_Config) {
                $options = $options->toArray();
            } elseif (!is_array($options)) {
                throw new \Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');
            }

            $this->setOptions($options);
        }
    }

    /**
     * Set autoloader
     *
     * @param  Zend_Loader_Autoloader $autoloader
     * @return Application
     */
    public function setAutoloader(\Zend_Loader_Autoloader $autoloader)
    {
        $this->_autoloader = $autoloader;
        return $this;
    }

    /**
     * Load configuration file of options base class proxy
     *
     * @return array
     */
    public function loadConfig($file)
    {
        return $this->_loadConfig($file);
    }
}
